/**
 * Created by zhangguowei on 2015/12/12.
 * */
var roleAuth = {
    //树形集合
    queryAllMenus: function () {
        $.post($basePath + "/queryAllMenuList ", {}, function (data) {
            var unSelectOption = "";
            var SelectOption = "";
            if (data) {
                for (var i = 0; i < data.length; i++) {
                    if ("1" == data[i].MULTIP) {
                        SelectOption += "<option value=\"" + data[i].INDX + "\">" + data[i].DESCRIPTION + "->" + data[i].NAME + "</option>"
                    } else {
                        unSelectOption += "<option value=\"" + data[i].INDX + "\">" + data[i].DESCRIPTION + "->" + data[i].NAME + "</option>"
                    }
                }
            }
            $("#keepRenderingSort").html(unSelectOption);
            $("#keepRenderingSort_to").html(SelectOption);
        });
    }, queryRoleMenu: function (roleIndx) {
        $.post($basePath + "/mgn/roleAuthority/queryRoleMenus ", {roleIndx: roleIndx}, function (data) {
            var unSelectOption = "";
            var SelectOption = "";
            if (data) {
                for (var i = 0; i < data.length; i++) {
                    if ("1" == data[i].MULTIP) {
                        SelectOption += "<option value=\"" + data[i].INDX + "\">" + data[i].DESCRIPTION + "->" + data[i].NAME + "</option>"
                    } else {
                        unSelectOption += "<option value=\"" + data[i].INDX + "\">" + data[i].DESCRIPTION + "->" + data[i].NAME + "</option>"
                    }
                }
            }
            $("#keepRenderingSort").html(unSelectOption);
            $("#keepRenderingSort_to").html(SelectOption);
        });
    }, initNew: function () {
        window.location.href = $basePath + "/mgn/roleAuthority/initNew";
    }, initEdit: function (gridId) {
        var jsonArr = getId(gridId);
        if (1 < jsonArr.length) {
            ShowMessages("对不起,您只能选中一条记录", "系统提示", "msgwaring", null, 0);
        } else if (0 == jsonArr.length) {
            ShowMessages("对不起,请选择需要修改的记录", "系统提示", "msgwaring", null, 0);
        } else {
            window.location.href = $basePath + "/mgn/roleAuthority/initEdit/" + jsonArr[0].indx;
        }
    }, updateRole: function (gridId, status) {

        var selectedId = $("#" + gridId).jqGrid("getGridParam", "selrow");
        if (!selectedId) {
            ShowMessages("对不起,您没有选中任何记录", "系统提示", "msgwaring", null, 0);
            return;
        } else {
            var showMsg = "";
            if ('0' == status) {
                showMsg = "禁用";
            } else if ('1' == status) {
                showMsg = "启用";
            } else {
                return false;
            }
            showConfirm("确定要"+showMsg+"选中的数据吗？", "确定要"+showMsg, function () {
                var selectedRowIds = $("#" + gridId).jqGrid("getGridParam", "selarrrow");
                var len = selectedRowIds.length;
                var jsonSeqId = "";
                for (var i = 0; i < len; i++) {
                    var rowData = $("#" + gridId + "").jqGrid("getRowData", selectedRowIds[i]);
                    jsonSeqId += rowData.indx;
                    jsonSeqId += ",";
                }
                jsonSeqId = jsonSeqId.substr(0, jsonSeqId.length - 1);
                $.ajax({
                    type: "post",
                    async: false,
                    dataType: "json",
                    url: $basePath + "/mgn/roleAuthority/deleteRoleInfo",
                    data: {"indxs": jsonSeqId ,'status':status},
                    success: function (result) {
                        if (result) {
                            showOKMessage("数据"+showMsg+"成功!", '', function () {
                                var jsonStr = customFormToData("SearchTable");
                                $("#" + gridId).jqGrid('setGridParam', {
                                    url: $basePath + "/mgn/roleAuthority/queryRoleByPage",
                                    postData: JSON.parse(jsonStr),
                                    page: 1
                                }).trigger("reloadGrid");
                            });
                        } else {
                            ShowMessages("数据"+showMsg+"失败", "系统提示", "msgwaring", null, 0);
                        }
                    }
                });
            });

        }
    }, initDetail: function (cellvalue, options, rowObject) {
        return "<a href='" + $basePath + "/mgn/roleAuthority/initDetail/" + rowObject.indx + "'>" + rowObject.indx + "</a>";
    }, roleEdit: function () {
        $("#keepRenderingSort_to option").attr("selected", true);
        $.post($basePath + "/mgn/roleAuthority/updateRoleInfo", $("#roleForm").serialize(), function (data) {
            showOKMessage("保存成功!");
        });
    }, saveRole: function () {
        $("#keepRenderingSort_to option").attr("selected", true);
        $.post($basePath + "/mgn/roleAuthority/saveRoleInfo", $("#roleForm").serialize(), function (data) {
            showOKMessage("保存成功!");
        });
    }, roleMenuSave: function () {
        var menuIndx = "";
        $("#keepRenderingSort_to>option").each(function () {menuIndx += $(this).val() + ","});
        $.post($basePath + "/mgn/roleAuthority/saveRoleMenu", {roleIndx: '10003', menuIndx: menuIndx}, function (data) {

        });
    }
};




